package online.xuping.center.account.impl;

import cn.hutool.core.collection.ListUtil;
import online.xuping.center.account.IAccountGroupService;
import online.xuping.center.account.domain.AccountGroupDomain;
import online.xuping.center.account.domain.AccountTypeDomain;
import online.xuping.common.SettingUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 处理账户组设置
 */
@Service
public class AccountGroupServiceImpl implements IAccountGroupService {
    @Override
    public List<AccountGroupDomain> findAllGroup() {
        List<String> list = SettingUtil.getList("config/account.setting", "accountGroup");
        List<AccountGroupDomain> re  = new ArrayList();
        list.stream().forEach(it->{
            String re1[] = it.split(":");
            AccountGroupDomain accountGroupDomain = new AccountGroupDomain();
            accountGroupDomain.setAccountGroupName(re1[0]);
            List<AccountTypeDomain> accountTypeList = new ArrayList<>();
            String types = re1[1];
            ListUtil.toList(types.split("\\|")).stream().forEach(it1->{
                accountTypeList.add(AccountTypeDomain.builder().accountTypeName(it1).build());
            });
            accountGroupDomain.setAccountTypeList(accountTypeList);
            re.add(accountGroupDomain);
        });
        return re;
    }
}
